package Cantella::DJabberd::Web::Controller::Admin::UserJid;

#the order the following IS RELEVANT
use base 'Cantella::DJabberd::Web::UI::Controller::Collection::CRUD';
use Reaction::Class;

__PACKAGE__->config
  (
   model_name => 'Admin',
   collection_name => 'user_jids',
   action =>
   { base => { Chained => '/admin/base', PathPart => 'jid' },
     create => { ViewPort =>
                 {
                  field_order => [qw(node user jabber_groups)],
                  Field => { node => { layout => 'field/mutable/string' }, },
                 },
               },
     update => { ViewPort =>
                 {
                  field_order => [qw(node user jabber_groups)],
                  Field => { node => { layout => 'field/mutable/string' }, },
                 },
               },
     list   => {
                ViewPort => {
                             excluded_fields => [qw/id node domain/],
                             field_order => [qw/jid user/],
                             Member =>
                             { Field =>
                               { user => { controller => 'Admin::User' } },
                             },
                            },
               },
     view   =>
     { ViewPort =>
       {
        field_order    => [qw/jid user jabber_groups/],
        excluded_fields => [qw/node domain id roster_groups roster_items
                               messages sent_messages recieved_messages /],
        Field => {
                  user => { controller => 'Admin::User' },
                  jabber_groups => { controller => 'Admin::JabberGroup' },
                 },
       },
     },
   },
  );

sub base :Action :CaptureArgs(0) {
  my ($self, $c) = @_;
  $c->stash->{submenu}->current_item('jids');
}

sub delete_all {}
sub _build_action_viewport_args {
  my $args = shift->next::method(@_);
  #remove the delete all action
  my $protos = $args->{list}->{action_prototypes};
  @$protos = grep { $_->{label} !~ /Delete all/i } @$protos;
  return $args;
}

1;
